﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using UnityEngine;

namespace Studio
{
	// Token: 0x0200053E RID: 1342
	public class BackgroundList : MonoBehaviour
	{
		// Token: 0x06002265 RID: 8805 RVA: 0x000CF8B8 File Offset: 0x000CDAB8
		public void UpdateUI()
		{
			this.SetSelect(this.select, false);
			this.select = this.listPath.FindIndex((string v) => v == Singleton<Studio>.Instance.sceneInfo.background);
			this.SetSelect(this.select, true);
		}

		// Token: 0x06002266 RID: 8806 RVA: 0x000CF910 File Offset: 0x000CDB10
		private void OnClickSelect(int _idx)
		{
			this.SetSelect(this.select, false);
			this.select = _idx;
			this.SetSelect(this.select, true);
			this.backgroundCtrl.Load((this.select == -1) ? string.Empty : this.listPath[_idx]);
		}

		// Token: 0x06002267 RID: 8807 RVA: 0x000CF96C File Offset: 0x000CDB6C
		private void SetSelect(int _idx, bool _flag)
		{
			StudioNode studioNode = null;
			if (this.dicNode.TryGetValue(_idx, out studioNode))
			{
				studioNode.select = _flag;
			}
		}

		// Token: 0x06002268 RID: 8808 RVA: 0x000CF998 File Offset: 0x000CDB98
		private void InitList()
		{
			for (int i = 0; i < this.transformRoot.childCount; i++)
			{
				UnityEngine.Object.Destroy(this.transformRoot.GetChild(i).gameObject);
			}
			this.transformRoot.DetachChildren();
			IEnumerable<string> files = Directory.GetFiles(UserData.Create("background"), "*.png");
			if (BackgroundList.callback0 == null)
			{
				BackgroundList.callback0 = new Func<string, string>(Path.GetFileName);
			}
			this.listPath = files.Select(BackgroundList.callback0).ToList<string>();
			this.CreateNode(-1, "なし");
			int count = this.listPath.Count;
			for (int j = 0; j < count; j++)
			{
				this.CreateNode(j, Path.GetFileNameWithoutExtension(this.listPath[j]));
			}
			this.select = this.listPath.FindIndex((string v) => v == Singleton<Studio>.Instance.sceneInfo.background);
			this.SetSelect(this.select, true);
		}

		// Token: 0x06002269 RID: 8809 RVA: 0x000CFAA0 File Offset: 0x000CDCA0
		private void CreateNode(int _idx, string _text)
		{
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.objectNode);
			gameObject.transform.SetParent(this.transformRoot, false);
			StudioNode component = gameObject.GetComponent<StudioNode>();
			component.active = true;
			component.addOnClick = delegate()
			{
				this.OnClickSelect(_idx);
			};
			component.text = _text;
			this.dicNode.Add(_idx, component);
		}

		// Token: 0x0600226A RID: 8810 RVA: 0x000CFB18 File Offset: 0x000CDD18
		private void Start()
		{
			this.InitList();
		}

		// Token: 0x0400237B RID: 9083
		[SerializeField]
		private GameObject objectNode;

		// Token: 0x0400237C RID: 9084
		[SerializeField]
		private Transform transformRoot;

		// Token: 0x0400237D RID: 9085
		[SerializeField]
		private BackgroundCtrl backgroundCtrl;

		// Token: 0x0400237E RID: 9086
		private List<string> listPath = new List<string>();

		// Token: 0x0400237F RID: 9087
		private Dictionary<int, StudioNode> dicNode = new Dictionary<int, StudioNode>();

		// Token: 0x04002380 RID: 9088
		private int select = -1;

		// Token: 0x04002382 RID: 9090
		[CompilerGenerated]
		private static Func<string, string> callback0;
	}
}
